<?PHP
/* * ************************************* */
/* * *********** IdeaLAN LLC ************* */
/* Configuration file here you can setup */
/* All the settings for the APC like    */
/* Add users, install modules, edit     */
/* Config file add stuff lol            */
/* * ************************************* */
/* * ************************************* */
/* SCRIPT: config.php        VER: 0.9b  */
/* AUTHOR: Lukasz Piekarski             */
/* E-mail: lukasz@idealan.net           */
/* UPDATE: 10.11.11						 */
/* * ************************************* */
/*
  CONFIG	+
  - ADD COMPANY INFORMATION, LOGO, TAX INFO, ETC.
  END CONFIG
 */

if (empty($_SESSION["sesid"])) {
    header("Location: ../in.php?e=0");
}
?>

<div id="content">
    <div id="left">
        <div class="naglowek"><div class="pkt"></div>Configuration</div>
        <ul id="me">
            <li <? if ($view == "") {
    echo "id=\"press\"";
} ?> ><a href="in.php?show=config">ACP Settings</a></li>
            <li <? if ($view == "cinfo") {
    echo "id=\"press\"";
} ?> ><a href="in.php?show=config&view=cinfo">Company Information</a></li>
            <li <? if ($view == "users") {
    echo "id=\"press\" ";
} ?> ><a href="in.php?show=config&view=users">User List</a></li>
            <li <? if ($view == "adduser") {
    echo "id=\"press\" ";
} ?> ><a href="in.php?show=config&view=adduser">Add a user</a></li>
            <li <? if ($view == "permusers") {
            echo "id=\"press\" ";
        } ?> ><a href="in.php?show=config&view=permusers">Permissions Users</a></li>
            <li <? if ($view == "permcat") {
            echo "id=\"press\" ";
        } ?> ><a href="in.php?show=config&view=permcat">Permissions Categories</a></li>
            <li <? if ($view == "modules") {
            echo "id=\"press\" ";
        } ?> ><a href="in.php?show=config&view=modules">Modules</a></li>
        </ul>
    </div>					

    <div id="right">
<?
if (!$view) {

    if ($conf_timeout == "0") {
        $st1 = "SELECTED";
    } else if ($conf_timeout == "600") {
        $st2 = "SELECTED";
    } else if ($conf_timeout == "1200") {
        $st3 = "SELECTED";
    } else if ($conf_timeout == "2400") {
        $st4 = "SELECTED";
    } else if ($conf_timeout == "3600") {
        $st5 = "SELECTED";
    }
    if ($conf_shosid == "1") {
        $ss1 = "SELECTED";
    } else if ($conf_shosid == "2") {
        $ss2 = "SELECTED";
    }

    $opt_al = array("NONE", "ACP", "WEB");
    $List_alin = dropdown("conf_alin", $opt_al, $conf_alin);
    $List_alou = dropdown("conf_alou", $opt_al, $conf_alou);
    ?>

            <div class='naglowek'><div class='pkt'></div>ACP SETTINGS</div>
            <div id='rightcont'>
                <div class='form_title'>&nbsp;</div>

                <form method='POST' action='modify.php?act=save' class='form_service'>
                    <input type='hidden' name='what' value='config'>
                    <input type='hidden' name='cat' value='settings'>

                    &nbsp;<u>Basic Information</u><br /><br />


                    <label for='conf_weburl'>Web URL:&nbsp;</label>
                    <input name="conf_weburl" type="text" class="input_form2" id="conf_weburl" value="<?php echo $conf_weburl ?>"><br />
                    <label for='conf_acpurl'>ACP URL:&nbsp;</label>
                    <input name="conf_acpurl" type="text" class="input_form2" id="conf_acpurl" value="<?php echo $conf_acpurl ?>"><br />

                    <br /><br />&nbsp;<u>Paths</u><br /><br />

                    <label for='conf_bpath'>Base Path:&nbsp;</label>
                    <input name="conf_bpath" type="text" class="input_form2" id="conf_bpath" value="<?php echo $conf_bpath ?>"><br />
                    <label for='conf_apath'>Addons Path:&nbsp;</label>
                    <input name="conf_apath" type="text" class="input_form2" id="conf_apath" value="<?php echo $conf_apath ?>"><br />
                    <label for='conf_mpath'>Modules Path:&nbsp;</label>
                    <input name="conf_mpath" type="text" class="input_form2" id="conf_mpath" value="<?php echo $conf_mpath ?>"><br />
                    <label for='conf_tpath'>Temp Path:&nbsp;</label>
                    <input name="conf_tpath" type="text" class="input_form2" id="conf_tpath" value="<?php echo $conf_tpath ?>"><br />

                    <br /><br />&nbsp;<u>Other Settings</u><br /><br />

                    <label for='conf_passmin'>Pass Min.Chars.:&nbsp;</label>
                    <input name="conf_passmin" type="text" class="input_form2" id="conf_passmin" value="<?php echo $conf_passmin ?>">
                    <label for='conf_passmax'>Pass Max.Chars.:&nbsp;</label>
                    <input name="conf_passmax" type="text" class="input_form2" id="conf_passmax" value="<?php echo $conf_passmax ?>">
                    <label for='conf_timeout'>Default TOut:&nbsp;</label>
                    <select name="conf_timeout" class="input_form" id="conf_timeout"><option value="0" <?php echo $st1 ?>>BY USER</option><option value="600" <?php echo $st2 ?>>10 Minutes</option><option value=\"1200\" <?php echo $st3 ?>>20 Minutes</option><option value=\"2400\" <?php echo $st4 ?>>40 Minutes</option><option value=\"3600\" <?php echo $st5 ?>>60 Minutes</option></select>
                    <label for='conf_shosid'>Show SESID:&nbsp;</label>
                    <select name="conf_shosid" id="conf_shosid" class="input_form"><option value="1" <?php echo $ss1 ?>> YES </option><option value="2" <?php echo $ss2 ?>> NO </option></select>

                    <br /><br />&nbsp;<u>After Login:</u><br /><br />
                    <label for='conf_alin'>Go To:&nbsp;</label>
                    $List_alin
                    <br /><br />&nbsp;<u>After Logout:</u><br /><br />
                    <label for='conf_alou'>Go To:&nbsp;</label>
                    $List_alou
                    <p>&nbsp;</p>
                    <p>

                        <input type="submit" class="button1" value="SAVE">
                </form>
                </p>
            </div>

        </div>
    <?php
} // END CONFIG

if ($view == "cinfo") {
    ?>
        <div class='naglowek'><div class='pkt'></div>COMPANY INFORMATION</div>
        <div id='rightcont'>
            <form method='POST' action='modify.php?act=save'>
                <input type='hidden' name='what' value='config'>
                <input type='hidden' name='cat' value='adduser'>
                <table style='width: 100%' class='editform1'>
                    <tr>
                        <td style='width: 145px' class='table1'>&nbsp;</td>
                        <td class='table2'>&nbsp;</td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>Company Name: </td>
                        <td class='table3'><input name="finfo_user_name" type="text" class="input_form" id="finfo_user_name" value=""></td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>Suite: </td>
                        <td class='table2'><input name="finfo_user_fname" type="text" class="input_form" id="finfo_user_fname" value=""></td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>Street: </td>
                        <td class='table2'><input name="finfo_user_fname" type="text" class="input_form" id="finfo_user_fname" value=""></td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>City: </td>
                        <td class='table2'><input name="finfo_user_lname" type="text" class="input_form" id="finfo_user_lname" value=""></td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>State: </td>
                        <td class='table2'><input name="finfo_user_phone" type="text" class="input_form" id="finfo_user_phone" value=""></td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>Zip Code: </td>
                        <td class='table2'><input name="finfo_user_email" type="text" class="input_form" id="finfo_user_email" value=""></td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>&nbsp;</td>
                        <td class='table2'>&nbsp;</td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>Phone#: </td>
                        <td class='table2'><input name="finfo_user_email" type="text" class="input_form" id="finfo_user_email" value=""></td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>Fax#: </td>
                        <td class='table2'><input name="finfo_user_email" type="text" class="input_form" id="finfo_user_email" value=""></td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>E-mail: </td>
                        <td class='table2'><input name="finfo_user_email" type="text" class="input_form" id="finfo_user_email" value=""></td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>Www: </td>
                        <td class='table2'><input name="finfo_user_email" type="text" class="input_form" id="finfo_user_email" value=""></td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>&nbsp;</td>
                        <td class='table2'>&nbsp;</td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>Tax %: </td>
                        <td class='table2'><input name="finfo_user_email" type="text" class="input_form" id="finfo_user_email" value=""></td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>&nbsp;</td>
                        <td class='table2'>&nbsp;</td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>&nbsp;</td>
                        <td class='table2'><input type="submit" class="button1" value="SAVE"></form></td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>&nbsp;</td>
                        <td class='table2'>&nbsp;</td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>&nbsp;</td>
                        <td class='table2'>&nbsp;You can download empty PNG with dimensions <a href='../g/logo_empty.png'>here</a> (righ click save as)</td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>&nbsp;</td>
                        <td class='table2'>&nbsp;</td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>Current Logo: </td>
                        <td class='table2'>
                            <form action="scripts/ajaxupload.php" method="post" name="standard_use" id="standard_use" enctype="multipart/form-data">
                                <p><input type="file" name="file" /> <br/><button onclick="ajaxUpload(this.form,'scripts/upload.php?upload=image&fL=../storage/','upload_area','File Uploading Please Wait...&lt;br /&gt;&lt;img src=\'../g/loader_light_blue.gif\' width=\'128\' height=\'15\' border=\'0\' /&gt;','&lt;img src=\'../g/error.gif\' width=\'16\' height=\'16\' border=\'0\' /&gt; Error in Upload, check settings and path info in source code.'); this.disabled=true; return false;">Upload Image</button></p></br>
                            </form>

                            <div id="upload_area">"; 
        <?php
        if (file_exists("./storage/logo.png")) {
            echo "</br><img src='./storage/logo.png' width='250' height='100' />";
        }
        ?>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td style='width: 145px' class='table1'>&nbsp;</td>
                        <td class='table2'>&nbsp;</td>
                    </tr>

                </table>
                <p>&nbsp;</p>
                <p>
                </p>
        </div>
        <?php
    } // END COMPANY INFORMATION

    if ($view == "adduser") {

        ?>
<div class='naglowek'><div class='pkt'></div>ADD A USER</div>
<div id='rightcont'>
<form method='POST' action='modify.php?act=save'>
<input type='hidden' name='what' value='config'>
<input type='hidden' name='cat' value='adduser'>
<table style='width: 100%' class='editform1'>
	<tr>
		<td style='width: 145px' class='table1'>&nbsp;</td>
		<td class='table2'>&nbsp;</td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>User Name:</td>
		<td class='table3'><input name="finfo_user_name" type="text" class="input_form" id="finfo_user_name" value=""></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>&nbsp;</td>
		<td class='table2'>&nbsp;</td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>First Name:</td>
		<td class='table2'><input name="finfo_user_fname" type="text" class="input_form" id="finfo_user_fname" value=""></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>Last: Name:</td>
		<td class='table2'><input name="finfo_user_lname" type="text" class="input_form" id="finfo_user_lname" value=""></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>Phone:</td>
		<td class='table2'><input name="finfo_user_phone" type="text" class="input_form" id="finfo_user_phone" value=""></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>E-mail:</td>
		<td class='table2'><input name="finfo_user_email" type="text" class="input_form" id="finfo_user_email" value=""></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>&nbsp;</td>
		<td class='table2'>&nbsp;</td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>Timeout:</td>
		<td class='table2'><select name="finfo_user_set_timeout" class="input_form"><option value="600">10 Minutes</option><option value="1200" SELECTED>20 Minutes</option><option value="2400">40 Minutes</option><option value="3600">60 Minutes</option></select></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>User Group:</td>
		<td class='table2'><select name="finfo_user_level" class="input_form"><option value="1">User</option><option value="2">Employee</option><option value="3">Manager</option><option value="4">Supervisor</option><option value="5">Administrator</option></select></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>Send E-mail?</td>
		<td class='table2'><select name="finfo_user_send" class="input_form"><option value="1">YES</option><option value="2">NO</option></select></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>&nbsp;</td>
		<td class='table2'>&nbsp;</td>
	</tr>

</table>
<p>&nbsp;</p>
<p>

    <input type="submit" class="button1" value="SAVE">
</form>
</p>
</div>
                    
<?php
    } // END ADD USER



    if ($view == "users") {

// ATTACHE THIS TO THE PAGE, YOU WANT THE NEXT LINK AND PREVIOUS TO BE DISPLAYED
        $rownumbers = SignupService::getInstance()->count($DBprefix);
        $linktest = "in.php?show=profile&view=logs";

        include "inc/pages.php";


// LETS GET USERS THAT ARE IN THE SYSTEM
        $execute_get_users = SignupService::getInstance()->getAllLimit($DBprefix,'user_id',$begin,25);
        ?>
        <div class='naglowek'><div class='pkt'></div>List of Users</div>
        <div id='rightcont'>
            <center><?php echo "$link_prev $pagejumpline $link_next" ?></center>
            <table class='editform1' style='width: 100%'>
                <tr>
                    <td width='30' class='tableLogsHeader'>ID</td>
                    <td width='115' class='tableLogsHeader'>USERNAME</td>
                    <td width='155' class='tableLogsHeader'>NAME</td>
                    <td width='200' class='tableLogsHeader'>E-MAIL</td>
                    <td width='156' class='tableLogsHeader'>LEVEL</td>
                    <td width='50' class='tableLogsHeader'>STATUS</td>
                    <td width='156' class='tableLogsHeader'>OPTIONS</td>
                </tr>
                <?php
                foreach($execute_get_users as $user) {
                    $user_id = $user->getId();
                    $user_fname = $user->getFname();
                    $user_lname = $user->getLname();
                    $user_phone = $user->getPhone();
                    $user_name = $user->getUsername();
                    $user_email = $user->getEmail();
                    $user_actnum = $user->getActnum();
                    $user_level =  $user->getLevel();
                    $user_adddate = $user->getAddDate();
                    $user_lastlogin = $user->getLastLogin();
                    $user_logindns = $user->getLoginDns();
                    $user_set_timeout = $user->getSetTimeout();
                    $user_set_lock = $user->getSetLock();
// CHECK LOCK
                    if ($user_id == "1") {
                        $show_lock = "";
                    } else if ($user_set_lock == 0) {
                        $show_lock = "<a href='modify.php?act=change&what=user&set=lock&to=1&uid=$user_id'><img src='../g/ico/lock.png'></a>";
                    } else {
                        $show_lock = "<a href='modify.php?act=change&what=user&set=lock&to=0&uid=$user_id'><img src='../g/ico/lock_delete.png'></a>";
                    }
                    if ($user_set_lock == 1) {
                        $show_flag = "<img src='../g/ico/flag_yellow.png'>";
                    } else if ($user_actnum == 0) {
                        $show_flag = "<img src='../g/ico/flag_green.png'>";
                    } else {
                        $show_flag = "<img src='../g/ico/flag_red.png'>";
                    }
                    if ($info_user_id == $user_id) {
                        $link_delete = "";
                    } else if ($user_id == "1") {
                        $link_delete = "";
                    } else {
                        $link_delete = "<a href=\"javascript:confirmDelete('modify.php?act=delete&what=user&uid=$user_id','DELETING: $user_name')\"><img src='../g/ico/user_delete.png'></a>";
                    }
                    if ($info_user_level < "5" AND $user_id == "1") {
                        $show_edit = "";
                    } else {
                        $show_edit = "<a href='in.php?show=config&view=edit&uid=$user_id'><img src='../g/ico/user_edit.png'></a>";
                    }
                    if ($user_name == "idealan") {
                        
                    } else {
                        echo "


       	 <tr>
	  		<td width='30' class='tableLogs'>$user_id</td>
  			<td width='115' class='tableLogs'>$user_name</td>
			<td width='145' class='tableLogs'>$user_lname $user_fname</td>
  			<td width='218' class='tableLogs'>$user_email</td>
  			<td width='156' class='tableLogsred'> " . @$ranks[$user_level] . " </td>
           		<td width='50' class='tableLogs'>$show_flag</td>            
           		<td width='156' class='tableLogs'>$show_edit $show_lock $link_delete</td>
		</tr>
";
                    }
                }

                echo "
</table>
<center>$link_prev $pagejumpline $link_next</center>
							</div>
";
            } // END VIEW USERS

            if ($view == "permusers") {

// ATTACHE THIS TO THE PAGE, YOU WANT THE NEXT LINK AND PREVIOUS TO BE DISPLAYED
                //$result = mysql_query("SELECT * FROM `" . $DBprefix . "access`");
                $rownumbers = AccessService::getInstance()->count($DBprefix);
                $linktest = "in.php?show=config&view=permusers";

                include "inc/pages.php";

                echo "
	<div class='naglowek'><div class='pkt'></div>View User Permissions</div>
	<div id='rightcont'>
";

                echo "
<center>
<form action='modify.php?act=save&what=config&cat=permissions&for=users' method='POST'>
<select class=\"input_form\" name='perm'>
<option value='0' SELECTED>&nbsp;</option>
<option value='2'>ALLOW</option>
<option value='1'>DENY</option>
</select>
 ACCESS FOR 

<select class=\"input_form\" name='uid'><option value='0'>&nbsp;</option>";

// LETS GET USERS THAT ARE IN THE SYSTEM
                $get_users = SignupService::getInstance()->getAllLimit($DBprefix,'user_id',$begin,25);
                
                foreach($get_users as $user) {   
                    $user_id = $user->getId();
                    $user_fname = $user->getFname();
                    $user_lname = $user->getLname();
                    $user_name = $user->getUsername();
                    $user_lvl = $user->getLevel();

                    if ($user_lvl !== "5") {
                        echo "<option value='$user_id'>$user_lname $user_fname ($user_name)</option>\n";
                    }
                }


                echo "</select> TO PAGE <select class=\"input_form\" name='pid'><option value='0' SELECTED>&nbsp;</option>";

// LETS GET CATEGORIES TO WHICH WE CAN CHANGE PERMISSIONS
                $get_cat = AccessPageService::getInstance()->getAllOrderLimit($DBprefix,'pagename',$begin,25);

                foreach($get_cat as $access) {  
                    $pageid = $access->getId();
                    $pagename = strtoupper($access->getName());
                    $pagesub = strtoupper($access->getSub());
                    $pageperm = $access->getPerm();
                    
                    if (empty($pagesub)) {

                        echo "<option value='$pageid'>$pagename</option>";
                    } else {
                        echo "<option value='$pageid'>$pagename -> $pagesub</option>";
                    }
                }

                echo "
</select> &nbsp;<input type='image' src='../g/ico/lock_add.png' name='submit'>
</form>
</center><br/>
";


                echo "
	<center>$link_prev $pagejumpline $link_next</center>
	<table class='editform1' style='width: 100%'>
       	 <tr>
	  		<td width='60' class='tableLogsHeader'>ACCESS</td>
  			<td width='115' class='tableLogsHeader'>USER</td>
			<td width='145' class='tableLogsHeader'>PAGE</td>
  			<td width='100' class='tableLogsHeader'>OPTIONS</td>

		</tr>
";
// LETS GET INFO FROM PERMSSION TABLE
                $execute_get_user_permissions = AccessService::getInstance()->getAllOrderLimit($DBprefix,'pageid',$begin,25);

                foreach($execute_get_user_permissions as $access) { 
                    $user_id = $access->getUserId();
                    $user_pageid = $access->getPageId();
                    $user_perm = $access->getPermission();
                    
                    if ($user_perm == 1) {
                        $show_perm = "DENY";
                    } else if ($user_perm == 2) {
                        $show_perm = "ALLOW";
                    }
                    if ($user_perm == 1) {
                        $show_perm_link = "<a href='modify.php?act=change&what=permission&for=user&uid=$user_id&pid=$user_pageid&to=2'><img src='../g/ico/lock_go.png'></A>";
                    } else if ($user_perm == 2) {
                        $show_perm_link = "<a href='modify.php?act=change&what=permission&for=user&uid=$user_id&pid=$user_pageid&to=1'><img src='../g/ico/lock_delete.png'></A>";
                    }

// GET USERNAME     
                    $user = SignupService::getInstance()->getUserInfoById($DBprefix,$user_id);
                    $user_perm1 = $user->getUsername();
                    $show_username = strtoupper($user->getUsername());

// GET NAME OF THE PAGE
                    $accessPage1 = AccessPageService::getInstance()->getAccessPagesByPageId($DBprefix,$user_pageid);
                    $show_pagename = strtoupper($accessPage1->getName());
                    $show_pagesub = strtoupper($accessPage1->getSub());

                    if (!empty($show_pagesub)) {
                        $show_subpagename = " -> $show_pagesub";
                    } else {
                        $show_subpagename = "";
                    }

                    echo "


       	 <tr>
	  		<td width='60' class='tableLogs'>$show_perm</td>
  			<td width='115' class='tableLogs'>$show_username</td>
			<td width='145' class='tableLogs'>$show_pagename $show_subpagename</td>
  			<td width='100' class='tableLogs'> $show_perm_link <a href='modify.php?act=delete&what=permission&for=user&uid=$user_id&pid=$user_pageid&perm=$user_perm'><img src='../g/ico/delete.png' alt='REMOVE!'></a></td>

		</tr>
";
                }

                echo "
</table>
<center>$link_prev $pagejumpline $link_next</center>
							</div>
";
            } // END PERMISSIONS FOR USERS

            if ($view == "permcat") {
                // GET CATEGORIES TO WICH U CAN ATTACHE PERMISSIONS

                echo "
<div class='naglowek'><div class='pkt'></div>CATEGORY PERMISSIONS</div>
	<div id='rightcont'>

<center>
<form action='modify.php?act=save&what=config&cat=permissions&for=categories' method='POST'>
<lable> PAGE NAME:</lable><input type=\"text\" name=\"pagename\" class=\"input_form\"> <lable> SUB PAGE:</lable><input type=\"text\" name=\"pagesub\" class=\"input_form\"> DEFAULT ACCESS: <select class=\"input_form\" name='defperm' size='1'><option value='1'>DENIED</option><option value='2'>ALLOWED</option></select> <input type='image' src='../g/ico/lock_add.png' name='submit'> 
</form></br>


		<form method='POST' action='modify.php?act=save'>
		<input type='hidden' name='what' value='config'>
		<input type='hidden' name='cat' value='edituser'>
		<input type='hidden' name='uid' value='$user_id'>

		<table style='width: 100%' class='editform1'>
			<tr>
				<td width='60' class='tableLogsHeader'>PAGE ID</td>
	  			<td width='115' class='tableLogsHeader'>NAME</td>
				<td width='145' class='tableLogsHeader'>SUB PAGE</td>
  				<td width='100' class='tableLogsHeader'>PERMISSION</td>
  				<td width='50' class='tableLogsHeader'>OPTIONS</td>
			</tr>
";
// LETS GET THE CATEGORIES
                $get_categories = AccessPageService::getInstance()->getAll($DBprefix);

                foreach($get_categories as $categories) {
                    $pageid = $categories->getId();
                    $pagename = $categories->getName();
                    $pagesub = $categories->getSub();
                    $pageperm = $categories->getPerm();

                    if (empty($pagesub)) {
                        $show_pagesub = "&nbsp;";
                    } else {
                        $show_pagesub = strtoupper($pagesub);
                    }
                    if ($pageperm == "1") {
                        $show_pageperm = "DENIED";
                        $show_unlock = "<a href='modify.php?act=change&what=permission&for=categories&to=2&pid=$pageid'><img src='../g/ico/lock_go.png'></a>";
                    } else if ($pageperm == "2") {
                        $show_pageperm = "ALLOWED";
                        $show_unlock = "<a href='modify.php?act=change&what=permission&for=categories&to=1&pid=$pageid'><img src='../g/ico/lock_delete.png'></a>";
                    }

                    echo "
			<tr>
				<td width='60' class='tableLogs'>$pageid</td>
	  			<td width='115' class='tableLogs'>" . strtoupper($pagename) . "</td>
				<td width='145' class='tableLogs'>$show_pagesub</td>
  				<td width='100' class='tableLogs'>$show_pageperm</td>
  				<td width='50' class='tableLogs'>$show_unlock <a href='modify.php?act=delete&what=permission&for=categories&pid=$pageid'><img src='../g/ico/delete.png'></a></td>
			</tr>
";
                }


                echo "
</table>
<p>&nbsp;</p>
</form>

</div>
                    
";
            } // END GET CATEGORIES TO WICH U CAN ATTACHE PERMISSIONS


            if ($view == "edit") {


// LETS GET USER INFO FROM THE SYSTEM
                $execute_get_users = SignupService::getInstance()->getUserInfoById($DBprefix,$_GET['uid']);

                foreach($execute_get_users as $user) {
                    $user = new Signup();
                    $user_id = $user->getId();
                    $user_fname = $user->getFname();
                    $user_lname = $user->getLname();
                    $user_phone = $user->getPhone();
                    $user_name = $user->getUsername();
                    $user_email = $user->getEmail();
                    $user_actnum = $user->getActnum();
                    $user_level = $user->getLevel();
                    $user_adddate = date("d.m.Y h:iA", $user->getAddDate());
                    $user_lastlogin = date("d.m.Y h:iA", $user->getLastLogin());
                    $user_logindns = $user->getLoginDns();
                    $user_set_timeout = $user->getSetTimeout();
                    $user_set_lock = $user->getSetLock();
                }

                if ($user_set_timeout == "600") {
                    $t1 = "SELECTED";
                }
                if ($user_set_timeout == "1200") {
                    $t2 = "SELECTED";
                }
                if ($user_set_timeout == "2400") {
                    $t3 = "SELECTED";
                }
                if ($user_set_timeout == "3600") {
                    $t4 = "SELECTED";
                }

                if ($user_level == "1") {
                    $l1 = "SELECTED";
                }
                if ($user_level == "2") {
                    $l2 = "SELECTED";
                }
                if ($user_level == "3") {
                    $l3 = "SELECTED";
                }
                if ($user_level == "4") {
                    $l4 = "SELECTED";
                }
                if ($user_level == "5") {
                    $l5 = "SELECTED";
                }




                echo "
<div class='naglowek'><div class='pkt'></div>EDITING USER: " . strtoupper($user_name) . "</div>
<div id='rightcont'>
<form method='POST' action='modify.php?act=save'>
<input type='hidden' name='what' value='config'>
<input type='hidden' name='cat' value='edituser'>
<input type='hidden' name='uid' value='$user_id'>
<table style='width: 100%' class='editform1'>
	<tr>
		<td style='width: 145px' class='table1'>&nbsp;</td>
		<td class='table2'>&nbsp;</td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>User Name:</td>
		<td class='table3'><input name=\"finfo_user_name\" type=\"text\" class=\"input_form\" id=\"finfo_user_name\" value=\"$user_name\" disabled></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>&nbsp;</td>
		<td class='table2'>&nbsp;</td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>First Name:</td>
		<td class='table2'><input name=\"finfo_user_fname\" type=\"text\" class=\"input_form\" id=\"finfo_user_fname\" value=\"$user_fname\"></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>Last: Name:</td>
		<td class='table2'><input name=\"finfo_user_lname\" type=\"text\" class=\"input_form\" id=\"finfo_user_lname\" value=\"$user_lname\"></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>Phone:</td>
		<td class='table2'><input name=\"finfo_user_phone\" type=\"text\" class=\"input_form\" id=\"finfo_user_phone\" value=\"$user_phone\"></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>E-mail:</td>
		<td class='table2'><input name=\"finfo_user_email\" type=\"text\" class=\"input_form\" id=\"finfo_user_email\" value=\"$user_email\"></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>&nbsp;</td>
		<td class='table2'>&nbsp;</td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>Timeout:</td>
		<td class='table2'><select name=\"finfo_user_set_timeout\" class=\"input_form\"><option value=\"600\" $t1>10 Minutes</option><option value=\"1200\" $t2>20 Minutes</option><option value=\"2400\" $t3>40 Minutes</option><option value=\"3600\" $t4>60 Minutes</option></select></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>User Group:</td>
		<td class='table2'><select name=\"finfo_user_level\" class=\"input_form\"><option value=\"1\" $l1>User</option><option value=\"2\" $l2>Employee</option><option value=\"3\" $l3>Manager</option><option value=\"4\" $l4>Supervisor</option><option value=\"5\" $l5>Administrator</option></select></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>&nbsp;</td>
		<td class='table2'>&nbsp;</td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>NewPass:</td>
		<td class='table2'><input name=\"finfo_user_npass\" type=\"password\" class=\"input_form\" id=\"finfo_user_npass\" value=\"\"></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>Again NewPass:</td>
		<td class='table2'><input name=\"finfo_user_anpass\" type=\"password\" class=\"input_form\" id=\"finfo_user_anpass\" value=\"\"></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>&nbsp;</td>
		<td class='table2'>&nbsp;</td>
	</tr>

</table>
<p>&nbsp;</p>
<p>

    <input type=\"submit\" class=\"button1\" value=\"SAVE\">
</form>
</p>
</div>
                    
";
            } // END EDIT USER !

            if ($view == "modules") {
                // MODULES
                // LETS GET MODULES THAT ARE IN THE SYSTEM
                $execute_get_modules = ModuleService::getInstance()->getAllOrdered($DBprefix,'mod_id');

                echo "
	<div class='naglowek'><div class='pkt'></div>LIST OF MODULES.</div>
	<div id='rightcont'>
	<center>$link_prev $pagejumpline $link_next</center>

	<table class='editform1' style='width: 100%'>
       	 <tr>
	  		<td width='30' class='tableLogsHeader'>ORDER</td>
  			<td width='115' class='tableLogsHeader'>MODULE NAME</td>
			<td width='145' class='tableLogsHeader'>LOCATION</td>
			<td width='40' class='tableLogsHeader'>VERSION</td>
			<td width='30' class='tableLogsHeader'>STATUS</td>
            <td width='50' class='tableLogsHeader'>OPTIONS</td>
		</tr>
	";

                $row_count = ModuleService::getInstance()->count($DBprefix);

                foreach($execute_get_modules as $module) {                    
                    $module = new Module();
                    $mod_id = $module->getId();
                    $mod_name = $module->getName();
                    $mod_location = $module->getLocation();
                    $mod_version = $module->getVer();
                    $mod_lud = $module->getLud();
                    $mod_lastup = $module->getLastUp();

                    if (!file_exists("inc/modules/$mod_location")) {
                        echo "	

       	 		<tr>
	  				<td width='30' class='tableLogs'>$mod_id</td>
  					<td width='115' class='tableLogs'>$mod_name</td>
					<td width='145' class='tableLogs'>$mod_location</td>
					<td width='40' class='tableLogs' onmouseover=\"Tip('$mod_lastup')\">$mod_version</td>
					<td width='30' class='tableLogs'><img src='../g/ico/module_error.png'></td>       
 					<td width='50' class='tableLogs'>FILE IS MISSING</td>
				</tr>

			";
                    } else {

                        $mod_fmodtime = filemtime("inc/modules/$mod_location");

                        if ($mod_fmodtime > $mod_lud) {
                            $mod_icon = "<a href='./inc/modules/$mod_location?view=verup&modid=$mod_id'><img src='../g/ico/module_vererr.png' onmouseover=\"Tip('Version Difference!')\"></a>";
                        } else {
                            $mod_icon = "<img src='../g/ico/module_installed.png'>";
                        }

                        if ($mod_id == "1") {
                            $link_order = "<a href='./inc/modules/$mod_location?view=order&change=down&modid=$mod_id'><img src='../g/ico/arrow_down.png'></a>";
                        } else if ($mod_id == $row_count) {

                            $link_order = "<a href='./inc/modules/$mod_location?view=order&change=up&modid=$mod_id'><img src='../g/ico/arrow_up.png'></a>";
                        } else {

                            $link_order = "<a href='./inc/modules/$mod_location?view=order&change=down&modid=$mod_id'><img src='../g/ico/arrow_down.png'></a> <a href='./inc/modules/$mod_location?view=order&change=up&modid=$mod_id'><img src='../g/ico/arrow_up.png'></a>";
                        }
                        echo "
       	 			<tr>
	  					<td width='30' class='tableLogs'>$mod_id</td>
  						<td width='115' class='tableLogs'>$mod_name</td>
						<td width='145' class='tableLogs'>$mod_location</td>
						<td width='40' class='tableLogs' onmouseover=\"Tip('$mod_lastup')\" >$mod_version</td>
						<td width='30' class='tableLogs'>$mod_icon</td>       
           				<td width='50' class='tableLogs'><a href='./inc/modules/$mod_location?view=backup'><img src='../g/ico/database_backup.png'></a> <a href=\"javascript:confirmDelete('inc/modules/$mod_location?view=remove','DELETING MODULE: $mod_name')\"><img src='../g/ico/module_delete.png'></a> $link_order&nbsp; </td>
					</tr>
			";
                    } // END IF FILE EXISTS
                }

                // LETS GET MODULES THAT ARE UPLOADED
                $path = "./inc/modules";
                $dirs = array();
                $files = array();

                $count_files = count($files);


                $dir = dir($path);

                while ($entry = $dir->read()) {
//&& substr($entry, -3) != ".gz"
                    if ($entry != "." && substr($entry, -5) != ".html" && $entry != "error_log") {
                        if (is_dir($entry)) {
                            if ($entry != ".." || $show_dotdirs) {
                                $dirs[] = $entry;
                            }
                        } else {
                            $files[] = $entry;
                        }
                    }
                }

                $dir->close();

                sort($files);

                foreach ($files as $file) {

                    list ($file_nad, $file_ext) = explode(".", $file);

                    list ($file_name, $file_date, $file_time) = explode("_", $file_nad);
                    $file_name = strtolower($file_name);

                    // LETS GET MODULES THAT ARE IN THE SYSTEM
                    $get_modules = "SELECT * FROM `" . $DBprefix . "modules` WHERE `mod_location` = '$file'";
                    $execute_get_modules = mysql_query($get_modules);

                    if (mysql_num_rows($execute_get_modules) == 0 && $file_ext == "php") {
                        echo "	
					<tr>
	  					<td width='30' class='tableLogs'>&nbsp;</td>
  						<td width='115' class='tableLogs'>&nbsp;</td>
						<td width='145' class='tableLogs'>$file</td>
						<td width='40' class='tableLogs'>&nbsp;</td>
						<td width='30' class='tableLogs'><img src='../g/ico/module_notinstalled.png'></td>       
 						<td width='50' class='tableLogs'><a href='inc/modules/$file?view=install'><img src='../g/ico/module_add.png'></a>&nbsp; </td>
					</tr>
				";
                    } else if ($file_ext == "gz") {
                        echo "	
					<tr>
	  					<td width='30' class='tableLogs'>&nbsp;</td>
  						<td width='115' class='tableLogs'>BACKUP</td>
						<td width='145' class='tableLogs'>$file</td>
						<td width='40' class='tableLogs'>&nbsp;</td>
						<td width='30' class='tableLogs'><img src='../g/ico/database.png'></td>       
 						<td width='50' class='tableLogs'><a href='inc/modules/$file'><img src='../g/ico/database_download.png'></a> <a href='inc/modules/$file_name.php?view=restore&file=$file'><img src='../g/ico/database_restore.png'></a> <a href='modify.php?act=delete&what=file&fn=$file'><img src='../g/ico/database_delete.png'></a>&nbsp; </td>
					</tr>
				";
                    }
                } // END FOR EACH





                echo "
				</table>
				<br />
				<form enctype='multipart/form-data' action='modify.php?act=save&what=config&cat=module' method='POST' class='editform1'>
				<br />
					<lable>Please choose a file: <input name='uploaded' type='file' /> </lable><br /><br />
					<input type='submit' value='Upload' class='button1' size='10' /><br /><br />
				</form>

			</div>
			";
            } // END MODULES
            ?>